package com.example.jack.community.view.login;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.support.percent.PercentRelativeLayout;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.example.jack.community.BaseActivity;
import com.example.jack.community.R;
import com.example.jack.community.model.login.Forget_bView;
import com.example.jack.community.persenter.login.ForgetPasswordPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.pedant.SweetAlert.SweetAlertDialog;

/**
 * 忘记密码修改密码页面
 */
public class Forget_bActivity extends BaseActivity implements Forget_bView{

    @BindView(R.id.register_button)
    Button registerButton;
    @BindView(R.id.activity_forget_b)
    PercentRelativeLayout activityForgetB;
    static String phonenum;
    private static final String TAG = "TonJie";
    @BindView(R.id.back)
    ImageView back;
    @BindView(R.id.forgetEdipassworda)
    EditText forgetEdipassworda;
    @BindView(R.id.forgetEdipasswordb)
    EditText forgetEdipasswordb;
    @BindView(R.id.textInputLayout)
    TextInputLayout textInputLayout;

    private ForgetPasswordPresenter forgetPassword = new ForgetPasswordPresenter(Forget_bActivity.this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_activity_forget_b);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        phonenum = intent.getStringExtra("phonenum");
        forgetPassword.attachView(this);
    }

    @OnClick({R.id.register_button, R.id.activity_forget_b})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.register_button:
                //第一次输入的密码
                String password_a = forgetEdipassworda.getText().toString().trim();
                //第二次输入的密码
                String password_b = forgetEdipasswordb.getText().toString().trim();
                Log.d(TAG, "onViewClicked: "+forgetEdipassworda+""+forgetEdipasswordb+""+phonenum);
                forgetPassword.forgetpassword(password_a, password_b, phonenum);
                break;
            case R.id.activity_forget_b:
                break;
        }
    }

    @Override
    public void ForgetSuccess(String msg) {
        Toast.makeText(this, "" + msg, Toast.LENGTH_SHORT).show();
        startActivity(new Intent(Forget_bActivity.this, Forget_cActivity.class));
    }

    @Override
    public void ForgetFail(String msg) {
        new SweetAlertDialog(this, SweetAlertDialog.ERROR_TYPE)
                .setTitleText(msg)
                .setContentText("")
                .show();
    }

    @Override
    public void showToast(String msg) {
        Toast.makeText(this, "" + msg, Toast.LENGTH_SHORT).show();
    }

    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }
}
